package services;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class UserDataServices {

	public int addData(UserData data) {
		try {
			return DBConnector.addUserData(data);
        } catch (ClassNotFoundException e1) {
                e1.printStackTrace();
        } catch (SQLException e) {
        	e.printStackTrace();
        	return -1; 
        }
		return -1;       
	}
	public boolean updateData(UserData data) {
		try {
			 DBConnector.updateUserData(data);
        } catch (ClassNotFoundException e1) {
                e1.printStackTrace();
        } catch (SQLException e) {
        	e.printStackTrace();
        	return false;
        }
		return true;       
	}
	public boolean deleteData(int id) {
		try {
			DBConnector.removeUserData(id);
        } catch (ClassNotFoundException e1) {
                e1.printStackTrace();
        } catch (SQLException e) {
        	e.printStackTrace();
        	return false;
        }
		return true;       
	}
	public List<UserData> getData(User user) {
		try {
			return DBConnector.getUserDataById(user.getId());
        } catch (ClassNotFoundException e1) {
                e1.printStackTrace();
        } catch (SQLException e) {
        	e.printStackTrace();
        }
		return new ArrayList<UserData>();
	}
	public List<UserData> getDataInterval(User user, Date startDate, Date endDate) {
		System.out.println("getinterval");
		try {
			return DBConnector.getUserDataByIdAndInterval(user.getId(), startDate, endDate);
        } catch (ClassNotFoundException e1) {
                e1.printStackTrace();
        } catch (SQLException e) {
        	e.printStackTrace();
        }
		return new ArrayList<UserData>();
	}
	
	public List<AlarmType> getAlarmTypes() {
		System.out.println("getalarmtypes");
		try {
			return DBConnector.getAlarmTypes();
        } catch (ClassNotFoundException e1) {
                e1.printStackTrace();
        } catch (SQLException e) {
        	e.printStackTrace();
        }
		return new ArrayList<AlarmType>(); 
	}
	
	public void addAlarmType(AlarmType type) {
		System.out.println("getalarmtypes");
		try {
			DBConnector.addAlarmType(type);
        } catch (ClassNotFoundException e1) {
                e1.printStackTrace();
        } catch (SQLException e) {
        	e.printStackTrace();
        }
	}
	
	public List<AlarmClock> getAlarmClocks(User user) {
		System.out.println("getalarmtypes");
		try {
			return DBConnector.getAlarmClocks(user);
        } catch (ClassNotFoundException e1) {
                e1.printStackTrace();
        } catch (SQLException e) {
        	e.printStackTrace();
        }
		return new ArrayList<AlarmClock>(); 
	}
	
	public int addAlarmClock(AlarmClock clock) {
		System.out.println("getalarmtypes");
		try {
			return DBConnector.addAlarmClock(clock);
        } catch (ClassNotFoundException e1) {
                e1.printStackTrace();
        } catch (SQLException e) {
        	e.printStackTrace();
        }
		return -1;
	}
	public boolean updateAlarmClock(AlarmClock clock) {
		try {
			 DBConnector.updateAlarmClock(clock);
       } catch (ClassNotFoundException e1) {
               e1.printStackTrace();
       } catch (SQLException e) {
    	   e.printStackTrace();
    	   return false;
       }
	   return true;
	}
	
	public boolean deleteAlarmClock(int id) {
		try {
			DBConnector.removeAlarmClock(id);
        } catch (ClassNotFoundException e1) {
                e1.printStackTrace();
        } catch (SQLException e) {
        	e.printStackTrace();
        	return false;
        }
		return true;       
	}
	
}
